<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{include :: header('会员类型列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mb-2">
    <div class="toolbar" id="toolbar" role="group">
        <form id="formId" class="form-inline">
            <a class="btn btn-success mr-1" onclick="$.operate.add()">
                <i class="fa fa-plus"></i> 添加
            </a>
            <input type="text" class="form-control mr-1" name="searchKey" placeholder="商品名称">
            <select name="status" class="form-control mr-1" th:with="type=${@dict.getType('qdx_state_type')}">
                <option value="">状态</option>
                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
            </select>
            <button type="button" class="btn btn-primary mr-1" onclick="$.table.search()">
                <i class="fa fa-search"></i>
                搜索
            </button>
            <button type="button" class="btn btn-default" onclick="$.form.reset()">
                <i class="fa fa-refresh"></i>
                重置
            </button>
        </form>
    </div>
    <table id="bootstrap-table" class="table-striped"></table>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('type:edit')}]];
    var removeFlag = [[${@permission.hasPermi('type:remove')}]];
    var statusDatas = [[${@dict.getType('qdx_state_type')}]];
    var prefix = "/member/type";

    $(function() {
        var options = {
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            url: prefix + "/list.json",
            createUrl: prefix + "/add.html",
            updateUrl: prefix + "/edit.html?id={id}",
            removeUrl: prefix + "/remove.json",
            modalName: "会员类型",
            columns: [
                {
                    field: 'id',
                    title: 'ID'
                },
                {
                    field: 'title',
                    title: '名称'
                },
                {
                    field: 'imageUrl',
                    title: '图片',
                    formatter: function(value, row, index) {
                        if (value === "" || value == null) {
                            return "<img class='img-circle img-xs' data-height='50' data-width='50' data-target='self' src='/static/img/user.png'/>"
                        } else {
                            return $.common.sprintf("<img class='img-circle img-xs' height='50' width='50' data-target='self' src='%s'/>",  value);
                        }
                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    width:'300',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\', \'800px\', \'500px\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        switch (row.status) {
                            case 0 :
                                actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="updateStatus(\'' + row.id + '\',\'' +1 + '\')"><i class="fa fa-toggle-on"></i>停用</a> ');
                                break;
                            case 1 :
                                actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="updateStatus(\'' + row.id + '\',\'' +0 + '\')"><i class="fa fa-toggle-off"></i>启用</a> ');
                                break;
                            default:
                        }
                        actions.push('<a class="btn btn-info btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="openCourseList(\'' + row.id + '\')"><i class="fa fa-graduation-cap"></i>会员课程</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    //启用与停用
    function updateStatus(id, status) {
        table.set();
        var str ="";
        if(status==1){
            str = "请确定执行停用操作"
        }else{
            str = "请确定执行启动操作"
        }
        $.modal.confirm(str, function() {
            var data = {"id":id,"status": status };
            $.operate.submit(prefix + "/status.json", "post", "json", data);
        });
    }

    //打开会员课程列表
    function openCourseList(id) {
        layer.open({
            type: 2,
            area: ['100%', '100%'],
            maxmin: false,
            title: "会员课程列表",
            content: "/member/course/list.html?id=" + id,
            // 弹层外区域关闭
            shadeClose: true
        });
    }
</script>
</body>
</html>